#include <StructDescr.h>

AskDoubleDialog::AskDoubleDialog(QWidget *parent)
{
	this->setupUi(this);
	this->setWindowTitle(QString("Set Item's caption"));
}

void AskDoubleDialog::on_lineEdit_textChanged()
{
	if(!checkInput(lineEdit->text()))	
	{
		this->buttonBox->setStandardButtons(QDialogButtonBox::Cancel);
		this->setWindowTitle("Input Error");
	}
	else
	{
		this->buttonBox->setStandardButtons(QDialogButtonBox::Cancel|QDialogButtonBox::Ok);
		this->setWindowTitle(QString("Set Item's caption"));
	}
}

void AskDoubleDialog::on_lineEdit_editingFinished()
{
	if(checkInput(this->lineEdit->text()))
	{
		this->buttonBox->button(QDialogButtonBox::Ok)->click();
	}
}

bool AskDoubleDialog::checkInput(QString &inpLine)
{
	boost::regex e("^-\{0,1\}\([0-9]\*\)[.]\([0-9]\*\)$");
	boost::match_results<std::string::const_iterator> what;
	if(0 == boost::regex_match(inpLine.toStdString(), what, e, boost::match_default | boost::match_partial))
	{
		return false;
	}
	return true;
}